<?php

class bn_session
{
    private $session_name;

    function __construct($session_name, $hash = 'sha386', $path = '/files/temp')
    {
        $this->session_name = $session_name;
        // if (session_status() == PHP_SESSION_NONE)
        //{
        ini_set('session.hash_function', $hash);
        ini_set('session.hash_bits_per_character', 6);
        ini_set('session.cookie_httponly', 1); //prevent xss
        ini_set('session.entropy_file', "/dev/urandom"); //(better entropy source)
        ini_set('session.cookie_lifetime', 0);

        session_save_path(basepath . $path);
        session_start();
        session_regenerate_id(true);
        //}
    }

    public function has_session()
    {
        return (boolean)!empty($_SESSION[$this->session_name]);
    }

    public function __get($name)
    {
        return $_SESSION[$this->session_name][$name];
    }

    public function __set($name, $value)
    {
        $_SESSION[$this->session_name][$name] = $value;
    }

    public function set_array($array)
    {
        if (!empty($array))
        {
            $_SESSION[$this->session_name] = null;
            foreach ($array as $key => $value)
            {
                $_SESSION[$this->session_name][$key] = $value;
            }
        }

    }
    
    public function get_array()
    {
        return $_SESSION[$this->session_name];
    }

    public function delete()
    {
        if (self::has_session())
            unset($_SESSION[$this->session_name]);
    }
}
?>